import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { MulterModule } from '@nestjs/platform-express';
import { TypeOrmModule } from '@nestjs/typeorm';
import envConfig from '../config/env';
import { AichatModule } from './aichat/aichat.module';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from './auth/auth.module';
import { CategoryModule } from './category/category.module';
import { MessageBoardModule } from './message-board/message-board.module';
import { PostsModule } from './posts/posts.module';
import { SpiderModule } from './spider/spider.module';
import { TagController } from './tag/tag.controller';
import { TagModule } from './tag/tag.module';
import { UserModule } from './user/user.module';
import { WorksTagModule } from './works/works-tag/works-tag.module';
import { WorksModule } from './works/works/works.module';
const mcx = require('multer-cos-x');
@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true, envFilePath: [envConfig.path] }),
    ConfigModule.forRoot({ isGlobal: true }),
    TypeOrmModule.forRootAsync({
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) => ({
        type: 'mysql',
        host: configService.get('DB_HOST', '127.0.0.1'),
        port: configService.get<number>('DB_PORT', 3306),
        username: configService.get('DB_USER', 'myblog'),
        password: configService.get('DB_PASSWORD', '123456'),
        database: configService.get('DB_DATABASE', 'myblog'),
        synchronize: true,//是否自动将实体类同步到数据库
        retryDelay: 500,//重试连接数据库间隙
        retryAttempts: 1,//重试连接数据库的次数
        dateStrings: ['TIMESTAMP'],
        timezone: "+08:00", // 设置时区
        entities: [__dirname + "/**/*.entity{.ts,.js}"],//实体文件
        autoLoadEntities: true,//如果为true，将自动加载实体 forFeature()方法注册的每个实体都将自动添加到配置对象的实体
        cache: false,//要启用缓存
        logging: true,//开启日志
      }),
    }),
    MulterModule.register({
      storage: mcx({
        cos: {
          // 必填参数
          SecretId: process.env.COS_KEY,
          SecretKey: process.env.COS_SECRET,
          Bucket: process.env.COS_BUCKET,
          Region: process.env.COS_REGION,
        },
      }),
    }),
    PostsModule,
    UserModule,
    AuthModule,
    CategoryModule,
    TagModule,
    WorksModule,
    WorksTagModule,
    MessageBoardModule,
    SpiderModule,
    AichatModule,
  ],
  controllers: [AppController, TagController],
  providers: [AppService],
})
export class AppModule { }
